﻿using msBsc.AppLogic.DataAlc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Seller
{
    public partial class mfOrderList : msBsc.Cls.mBPDealer
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void getOrderList()
        {
            string userId = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(userId))
            {
                return;
            }
            string pageRows = this.GetParamHtValue("pageRows");
            string pageNum = this.GetParamHtValue("pageNum");
            string orderStatus = this.GetParamHtValue("orderStatus");
            using (msBsc.AppLogic.DataAlc.CBizOrdersInfo orderInfo = new AppLogic.DataAlc.CBizOrdersInfo())
            {
                int pRows = 10;
                int.TryParse(pageRows, out pRows);
                int pNum = 1;
                int.TryParse(pageNum, out pNum);
                int oStatus = 0;
                int.TryParse(orderStatus, out oStatus);
                OrderStatusEnum oStatusEnum = OrderStatusEnum.AllOrders;
                if ((OrderStatusEnum)oStatus == OrderStatusEnum.Finished)
                {
                    oStatusEnum = OrderStatusEnum.Finished;
                }
                else if ((OrderStatusEnum)oStatus == OrderStatusEnum.WaitingCheck)
                {
                    oStatusEnum = OrderStatusEnum.WaitingCheck;
                }
                else if ((OrderStatusEnum)oStatus == OrderStatusEnum.SolderChecked)
                {
                    oStatusEnum = OrderStatusEnum.SolderChecked;
                }
                DataSet ds = orderInfo.GetOrderList("", userId, oStatusEnum, pNum, pRows);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    this.ExecJScript(@"alert(""您没有该类型订单"");$(""#order_list"").html("""");");
                    return;
                }
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript("setOrderList(" + ret + ")");
            }
        }

        /// <summary>
        /// 删除订单
        /// </summary>
        /// Author:任延华
        /// Creation date:2015-07-27
        private void deleteOrder()
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                this.Alert("请选择订单");
                return;
            }
            string djakcId = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(djakcId))
            {
                //页面跳转
                this.Alert("请登录");
                this.ExecJScript(@"window.location.reload()");
            }
            using (msBsc.AppLogic.DataAlc.CBizOrdersInfo orderInfo = new AppLogic.DataAlc.CBizOrdersInfo())
            {
                string ret = orderInfo.DeleteOrder(djakcId, orderId, true);
                if (ret != "OK")
                {
                    this.Alert(ret);
                }
                else
                {
                    //页面跳转
                    this.Alert("删除成功");
                    this.ExecJScript(@"window.location.reload()");
                }
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "getOrderList")
            {
                getOrderList();
            }
            else if (this.strAction == "deleteOrder")
            {
                deleteOrder();
            }
        }
    }
}